package com.hz.copyingsystem.controller;

import com.hz.common.utils.ResponseData;
import com.hz.common.utils.ResponsePage;
import com.hz.copyingsystem.entity.FixedInformationDicEntity;
import com.hz.copyingsystem.service.FixedInformationDicService;
import com.hz.copyingsystem.service.SelectedCopyingExamplesService;
import com.hz.copyingsystem.vo.CopyingExamplesStructureTypeVo;
import com.hz.copyingsystem.vo.SelectedCopyingExamplesVo;
import com.hz.utils.FixedInformationName;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;


/**
 * @author cyl_txw
 * @email cyl_txw@gmail.com
 * @date 2023-05-09 15:02:11
 */
@RestController
@RequestMapping("selectedCopyingExamples")
@Api(tags = "精临例字")
public class SelectedCopyingExamplesController {

    @Autowired
    private FixedInformationDicService fixedInformationDicService;

    @Autowired
    private SelectedCopyingExamplesService copyingExamplesService;

    /**
     * 精临例字结构种类获取
     */
    @ApiOperation("精临例字结构种类获取")
    @GetMapping("/examplesType/get")
    public ResponseData<CopyingExamplesStructureTypeVo> examplesTypeGet() {
        // 查询所有的精临例字结构名称
        List<FixedInformationDicEntity> fixedInformationDicList = fixedInformationDicService.queryByName(FixedInformationName.SE_CO_EXAMPLES_STRUCTURE);
        // 映射成vo List
        List<CopyingExamplesStructureTypeVo> coExamStrucTypeVoList = fixedInformationDicList.stream()
                .map(fixedInformationDic -> new CopyingExamplesStructureTypeVo(
                        fixedInformationDic.getId(),
                        fixedInformationDic.getFixedInformationContent()
                ))
                .collect(Collectors.toList());
        return ResponseData.success(coExamStrucTypeVoList);
    }

    /**
     * 精临例字分页查询
     */
    @ApiOperation("精临例字分页列表")
    @PostMapping("/examples/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页数", paramType = "query", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "condition", value = "模糊查询条件", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "sid", value = "结构种类id", paramType = "query", dataType = "Long", required = false)
    })
    public ResponseData<ResponsePage<List<SelectedCopyingExamplesVo>>> examplesPage(@RequestParam("curPage") Integer curPage,
                                                                                    @RequestParam("pageSize") Integer pageSize,
                                                                                    @RequestParam(value = "condition", required = false) String condition,
                                                                                    @RequestParam(value = "sid", required = false) Long sid) {

        List<SelectedCopyingExamplesVo> copyingSteleCalligraphyList = copyingExamplesService.queryExamples(curPage, pageSize, sid, condition);

        ResponsePage<List<SelectedCopyingExamplesVo>> page = new ResponsePage<>(
                copyingSteleCalligraphyList,
                copyingExamplesService.queryExamplesNum(sid, condition),
                pageSize
        );
        return ResponseData.success(page);
    }
}
